package com.heima.media.controller;

import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.NewsAuthDto;
import com.heima.media.dto.WmNewsDto;
import com.heima.media.dto.WmNewsPageDto;
import com.heima.media.entity.WmNews;
import com.heima.media.service.IWmNewsService;
import com.heima.media.vo.WmNewsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 自媒体图文内容信息表 前端控制器
 * </p>
 *
 * @author syl
 * @since 2021-11-03
 */
@RestController
@RequestMapping("/api/v1/news")
@Api(tags = "自媒体图文内容信息表接口")
@CrossOrigin
public class WmNewsController {

    @Autowired
    private IWmNewsService wmNewsService;

    @PostMapping("/list")
    @ApiOperation(value = "listByCondition", notes = "自媒体文章列表查询")
    @ApiModelProperty(name = "dto", dataType = "WmNewsPageDto", required = true)
    public ResponseResult listByCondition(@RequestBody WmNewsPageDto dto) {
        return wmNewsService.listByCondition(dto);
    }


    @GetMapping("/{id}")
    @ApiOperation(value = "getById", notes = "自媒体文章-查看")
    @ApiModelProperty(name = "id", dataType = "Integer", required = true)
    public ResponseResult getById(@PathVariable("id") Integer id) {
        WmNews wmNews = wmNewsService.getById(id);
        return ResponseResult.okResult(wmNews);
    }

    @PostMapping("/submit")
    @ApiOperation(value = "submit", notes = "自媒体文章-发布、修改，保存草稿")
    @ApiModelProperty(name = "dto", dataType = "WmNewsDto", required = true)
    public ResponseResult submit(@RequestBody WmNewsDto dto) {
        return wmNewsService.submit(dto);
    }


    @PutMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto wmNewsDto){
        return wmNewsService.downOrUp(wmNewsDto);
    }


    /**
     * 查询文章列表
     * @param dto
     * @return
     */
    @PostMapping("/findPageByName")
    public ResponseResult findPageByName(@RequestBody NewsAuthDto dto){
        return wmNewsService.findPageByName(dto);
    }

    /**
     * 查询文章详情(带作者信息)
     * @param id
     * @return
     */
    @GetMapping("/findNewsVoById/{id}")
    public ResponseResult<WmNewsVo> findNewsVoById(@PathVariable("id") Integer id){
        return wmNewsService.findNewsVoById(id);
    }

    @PostMapping("/auth_fail")
    public ResponseResult authFail(@RequestBody NewsAuthDto dto) {
        return wmNewsService.auth(dto, 0);
    }
    @PostMapping("/auth_pass")
    public ResponseResult authPass(@RequestBody NewsAuthDto dto) {
        return wmNewsService.auth(dto, 1);
    }
}

